/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OLA_BASE_UTILS_H
#define OLA_BASE_UTILS_H

#include <stdbool.h>
#include "cJSON.h"
#include "ola_sdk_api.h"

#ifdef __cplusplus
extern "C" {
#endif

#define OLA_ARRAY_SIZE(_arr) (sizeof(_arr)/sizeof((_arr)[0]))

void OlaPutNullAfterFree(void **ptr);

char *OlaGetJsonString(const cJSON *json, const char *key);

int OlaGetJsonNumber(const cJSON *json, const char *key, int *value);

char *OlaCopyJsonString(const cJSON *object, const char *name);

void OlaClearJsonString(cJSON *object);

int OlaIsOvertime(bool *state, unsigned long long baseTime, unsigned long long maxTime);

unsigned long long OlaDeltaTime(unsigned long long timeNew, unsigned long long timeOld);

char *OlaMallocAndCopyStr(const char *src, unsigned int srcLen);

void OlaDataFree(OlaData *data);

bool IsStrInvalid(const char *str, unsigned int minLen, unsigned int maxLen);

int OlaHexify(unsigned char *outBuf, unsigned int outLen,
    const unsigned char *inBuf, unsigned int inLen, bool upper);

#ifdef __cplusplus
}
#endif

#endif /* OLA_BASE_UTILS_H */